<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>产品管理</title>
    #include("common/header.html")
    <link rel="stylesheet" href="/admin/css/table.css"/>
</head>

<body>
<div class="admin-main">

    <blockquote class="layui-elem-quote">
        <a href="javascript:;" class="layui-btn layui-btn-small" id="addProp">
            <i class="layui-icon">&#xe608;</i> 添加比例
        </a>
    </blockquote>
    <fieldset class="layui-elem-field">
        <legend>产品列表</legend>
        <div class="layui-field-box layui-form">
            <table class="layui-table admin-table">
                <thead>
                    <tr>
                        <th>最小</th>
                        <th>最大</th>
                        <th>提拥比例</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    #foreach($item in $data)
                    <tr>
                        <th>$!item.min</th>
                        <th>$!item.max</th>
                        <th>$!item.value</th>
                        <th>
                            <a onclick="editProp($item.id)" class="layui-btn layui-btn-normal layui-btn-mini">修改</a>
                            <a onclick="delProp($item.id)" class="layui-btn layui-btn-normal layui-btn-mini">删除</a>
                        </th>
                    </tr>
                    #end
                </tbody>
            </table>
        </div>
    </fieldset>
</div>
</body>

<script type="text/javascript">

    var layerProp;
    layui.use('layer', function () {
        layerProp = layui.layer;
    });

    $("#addProp").on("click", function () {
        layer.open({
            type: 2,
            title: '添加比例',
            shadeClose: true,
            shade: false,
            zIndex: 99999999,
            maxmin: true, //开启最大化最小化按钮
            area: ['600px', '300px'],
            content: '/admin/prop/add/'+$pid,
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                var body = layer.getChildFrame('body',index);
                var validate = body.find("#validate").validator();
                var pid = body.find("#pid").val();
                var min = body.find("#min").val();
                var max = body.find("#max").val();
                var value = body.find("#value").val();

                if(!validate.check()){return;}

                $.ajax({
                    url: "/admin/prop/",
                    type: "post",
                    dataType: "json",
                    data: {"pid": pid, "min": min,"max":max,"value":value},
                    success: function (r) {
                        console.log(r);

                        if(r.code == -1){
                            layer.msg(r.msg);
                            return;
                        }
                        layer.close(index);
                        layer.msg('添加成功!',{time:1000}, function(){
                            //关闭后的操作
                            location.reload(index);
                        });
                    }
                });

            }
        });
    });

    function editProp(id) {
        layer.open({
            type: 2,
            title: '修改比例',
            shadeClose: true,
            shade: false,
            zIndex: 99999999,
            maxmin: true, //开启最大化最小化按钮
            area: ['600px', '300px'],
            content: '/admin/prop/edit/'+id,
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                var body = layer.getChildFrame('body',index);
                var validate = body.find("#validate").validator();
                var id = body.find("#id").val();
                var min = body.find("#min").val();
                var max = body.find("#max").val();
                var value = body.find("#value").val();

                if(!validate.check()){return;}

                $.ajax({
                    url: "/admin/prop/",
                    type: "put",
                    dataType: "json",
                    data: {"id": id, "min": min,"max":max,"value":value},
                    success: function (r) {
                        console.log(r);

                        if(r.code == -1){
                            layer.msg(r.msg);
                            return;
                        }
                        layer.close(index);
                        layer.msg('修改成功!',{time:1000}, function(){
                            //关闭后的操作
                            location.reload(index);
                        });
                    }
                });

            }
        });
    }

    function delProp(id) {
        //询问框
        layer.confirm('确定删除?', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $.ajax({
                url: "/admin/prop/"+id,
                type: "delete",
                dataType: "json",
                success: function (r) {
                    console.log(r);

                    if(r.code == -1){
                        layer.msg(r.msg);
                        return;
                    }
                    layer.msg('删除成功!',{time:1000}, function(){
                        //关闭后的操作
                        location.reload();
                    });
                }
            });
        });
    }
    
    function info(id) {
        
    }

</script>

</html>